<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <!--定义移动端缩放，比例变化-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客发布</title>
    <!--css引入-->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/me.css" th:href="@{/css/me.css}">
    <!--引入文本输入框编辑器的css-->
    <link rel="stylesheet" href="/lib/editor/css/editormd.min.css">
</head>
<body>


<!--nav:导航部分-->
<!--条:segment;黑色:inverted反转色-->
<nav class="ui attached segment  m-padded-tb-min m-shadow-small" style="background: #393D49;">
    <div class="ui container">
        <!--组件部分-->
        <div class="ui inverted secondary stackable menu fluid large">
            <!--3个标志部分-->
            <a href="/admin/index"><h1 class="ui teal header item">MBlog</h1></a>
            <a href="/admin/blogs_manage" class="active item m-text-lfat m-mobile-hide" id="002"><i class="home icon"></i>博客</a>
            <a href="/admin/types_manage" class="item m-text-lfat m-mobile-hide" id="003"><i class="idea icon"></i>分类</a>
            <a href="/admin/tags_manage" class="item m-text-lfat m-mobile-hide" id="004"><i class="tags icon"></i>标签</a>
            <!--用户登录导航栏-->
            <div class="right menu m-mobile-hide item  m-padded-tb-min" id="005">
                <div class=" ui dropdown item">
                    <div class="text">
                        <img class="ui avatar image" src="/image/4.png" th:src="@{${session.user.avatar}}">
                        <span th:text="${session.user.username}">admin</span>
                    </div>
                    <i class="dropdown icon"></i>
                    <div class="menu">
                        <a href="/admin/blogs_manage" class="item m-text-thin ">个人中心</a>
                        <a href="/logout" class="item m-text-thin ">退出登录</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <a href="#" class="ui menu icon button m-right-top m-mobile-show" id="001" style="background: #393D49;">
        <div class="ui vertical animated button tiny">
            <div class="hidden content ">菜单</div>
            <div class="visible content ">
                <i class="sidebar icon"></i>
            </div>
        </div>
    </a>
</nav>
<!--二级导航:pointing:下面有个小箭头-->
<div class="ui container m-container-normal">
    <div class="ui  pointing menu m-margin-tb-medium">
        <div class="right menu">
            <a href="/admin/blogs_manage-input" class="active teal item m-text-max">发布</a>
            <a href="/admin/blogs_manage" class="item">列表</a>
        </div>
    </div>
</div>

<!--中间博客发布-->
<div class="m-padded-tb-small attached">
    <div class="ui container  m-container-normal typo typo-selection">
        <h3 style="text-align: center;color: #393D49" class="ui  block header m-margin-t-small m-text-spaced attached">
            创作中...
        </h3>
        <form id="blog_form" action="#" th:action="@{/admin/blogs_add}" method="post" class="ui form segment m-padded-tb-min attached">
            <!--表示提交表单还是保存-->
            <input name="published" type="hidden">
            <!--required:表单验证-->
            <div class="required field">
                <div class="ui left labeled input m-margin-tb-small ">
                    <!--下拉选择框-->
                    <!--blue basic label:设置颜色；compact和文字大小相同-->
                    <div class="ui selection dropdown compact blue basic label">
                        <!--隐藏域内容 1：代表原创；2：代表转载；3：代表翻译-->
                        <input type="hidden" name="flag" value="原创">
                        <i class="dropdown icon"></i>
                        <div class="text">原创</div>
                        <div class="menu">
                            <div class="item" data-value="原创">原创</div>
                            <div class="item" data-value="转载">转载</div>
                            <div class="item" data-value="翻译">翻译</div>
                        </div>
                    </div>
                    <!--标题输入框-->
                    <input type="text" name="title" placeholder="标题">
                </div>
                <!--博客内容，插件-->
                <div class="field">
                    <div id="md-content" style="z-index: 1">
                        <textarea name="content" placeholder="输入内容" style="display: none"></textarea>
                    </div>

                </div>
            </div>
            <!--选择框-->
            <div class="three fields">
                <!--类别-->
                <div class="required field">
                    <div class="ui left labeled input m-margin-tb-small">
                        <div class="ui selection dropdown">
                            <input type="hidden" name="type.id"><!--自动分装到blog对象的属性中，定义形式要注意，要和属性中的对应-->
                            <i class="dropdown icon"></i>
                            <div class="default text">类别</div>
                            <div class="menu">
                                <div th:each =" type : ${types}" th:data-value="${type.id}" th:text="${type.name}"
                                     class="item" data-value="1">基础技能</div>
                            </div>
                        </div>
                    </div>
                </div>
                <!--标签-->
                <div class="field">
                    <div class="ui left labeled input m-margin-tb-small">
                        <div class="ui multiple search selection dropdown">
                            <input type="hidden" name="tagIds">
                            <i class="dropdown icon"></i>
                            <div class="default text">标签</div>
                            <div class="menu">
                                <div th:each =" tag : ${tags}" th:data-value="${tag.id}" th:text="${tag.name}"
                                     class="item" data-value="1">javaSE</div>
                            </div>
                        </div>
                    </div>
                </div>

                <!--三个组件按钮-->
                <div class="inline fields ">
                    <!--推荐到首页-->
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" name="recommend" id="recommend" checked>
                            <label for="recommend">推荐</label>
                        </div>
                    </div>
                    <!--转载信息-->
                    <div class="field">
                        <div class="ui checkbox ">
                            <input type="checkbox" name="shareContent" id="shareContent">
                            <label for="shareContent">转载声明</label>
                        </div>
                    </div>
                    <!--开启赞赏功能-->
                    <div class="field">
                        <div class="ui checkbox ">
                            <input type="checkbox" name="appreciation" id="appreciation">
                            <label for="appreciation">赞赏</label>
                        </div>
                    </div>
                    <!--开启评论-->
                    <div class="field">
                        <div class="ui checkbox ">
                            <input type="checkbox" name="commentabled" id="commentabled">
                            <label for="commentabled">评论</label>
                        </div>
                    </div>
                </div>
            </div>
            <!--首图片地址-->
            <div class="required field m-margin-bottom-medium">
                <div class="ui left labeled input">
                    <label  class="ui blue basic label">首图</label>
                    <input type="text" name="firstPicture" placeholder="展示页图片引用地址">
                </div>
            </div>
            <!--博客首页描述-->
            <div class="required field">
                <textarea name="description" placeholder="博客首页展示描述" maxlength="200"></textarea>
            </div>
            <!--存放错误信息-->
            <div class="ui error message"></div>
            <!--三个提交按钮-->
            <div class="inline fields m-right">
                <!--返回按钮:没设置type默认为提交表单-->
                <div class="field">
                    <button type="button" onclick="window.history.go(-1)"
                            class="ui grey small button m-margin-tb-small"><i
                            class="reply icon"></i>返回
                    </button>
                </div>
                <!--保存按钮-->
                <div class="field">
                    <button type="button" id="save-btn" class="ui teal small button  m-margin-tb-small"><i
                            class="save icon"></i>保存
                    </button>
                </div>
                <!--提交按钮-->
                <div class="field">
                    <button type="button" id="publish-btn" class="ui blue small button  m-margin-tb-small"><i
                            class="edit icon"></i>发布
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>

<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

<!--jquery引入-->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<!--js引入-->
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
<!--文本输入框的插件的js引入-->
<script src="/lib/editor/editormd.min.js"></script>

<!--页面的js-->
<script>
    <!--文本输入框的插件的js-->
    var contentEditor;
    $(function() {
        contentEditor = editormd("md-content", {
            width   : "100%",
            height  : 640,
            syncScrolling : "single",
            path    : "/lib/editor/lib/"
        });
    });

    /*适应手机端*/
    $("#001").click(function () {
        $("#002").toggleClass('m-mobile-hide');
        $("#003").toggleClass('m-mobile-hide');
        $("#004").toggleClass('m-mobile-hide');
        $("#005").toggleClass('m-mobile-hide');
        $("#006").toggleClass('m-mobile-hide');
        $("#007").toggleClass('m-mobile-hide');
    });
    /*下拉框*/
    $('.ui.dropdown').dropdown({});

    /*提交的表单验证*/
    $('.ui.form').form({
        fields: {
            title: {
                identifier: 'title',
                rules: [{
                    type: 'empty',
                    prompt: '请输入博客标题'
                }]
            },
            content: {
                identifier: 'content',
                rules: [{
                    type: 'empty',
                    prompt: '请输入博客内容'
                }]
            },
            typeId: {
                identifier: 'type.id',
                rules: [{
                    type: 'empty',
                    prompt: '请输入博客分类'
                }]
            },
            firstPicture: {
                identifier: 'firstPicture',
                rules: [{
                    type: 'empty',
                    prompt: '请输入博客首图地址'
                }]
            },
            description: {
                identifier: 'description',
                rules: [{
                    type: 'empty',
                    prompt: '请输入博客首页描述'
                }]
            }
        }
    });

    /*提交和保存的按钮动作*/
    $('#save-btn').click(function () {
        /*点击后name为published的隐藏域保存false的值*/
        $('[name="published"]').val(false);
        /*提交表单*/
        $('#blog_form').submit();
    });
    $('#publish-btn').click(function () {
        /*点击后name为published的隐藏域保存true的值*/
        $('[name="published"]').val(true);
        /*提交表单*/
        $('#blog_form').submit();
    });

</script>
</body>
</html>